package cn.test.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.test.bean.User;
import cn.test.dao.UserDao;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Override
	public void saveUser(User user) {
		this.getHibernateTemplate().save(user);

	}

	@Override
	public void removeUser(User user) {
		this.getHibernateTemplate().delete(user);

	}

	@Override
	public User findUserById(Integer id) {
		User user=(User)this.getHibernateTemplate().get(User.class, id);
		return user;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User> findAllUsers() {
		String hql="from User user order by user.id desc";
		List<User> list=(List<User>)this.getHibernateTemplate().find(hql);
		return list;
	}

	@Override
	public void updateUser(User user) {
		this.getHibernateTemplate().update(user);

	}

}
